import { UPDATE_NAME, GET_USERINFO } from '../mutations-type'
import { getLogin } from '../../api/common'
const app = {
    state: {
        userName: '',
        userInfo: {
        }
    },
    mutations: {
        [UPDATE_NAME](state, name) {//keyjiu  是名称  相当于自定义事件 value 就是回调函数的参数
            state.userName = name
            //函数体内，必须是同步， 不能有异步?工具要检测原仓库数据的改变
        },
        [GET_USERINFO](state, obj) {
            state.userInfo = obj
        }

    },
    actions: {
        async getLogin({ commit }, obj) {
            let userInfo = await getLogin(obj)
            commit('GET_USERINFO', userInfo.data)
            console.log(333,userInfo)
            if (userInfo.data.status == 0) {
                localStorage.setItem('token', userInfo.data.token)
                localStorage.setItem('username', userInfo.data.data.username)
            } else {
                alert(userInfo.data.msg)
            }
        }
    }

}

export default app